package com.wlc.base.array;

/**
 * @author 王立朝 wanglichao@champion-credit.com
 * @description 数组
 * @date 2021-06-24 10:07
 */
public class ArrayDemo {


    /**
     * 数组长度，数组定义和声明
     */
    public void method01() {
        // 声明数组
        int[] arrays = new int[10];
        // 对数组进行赋值
        arrays[0] = 1;
        arrays[1] = 2;
        arrays[2] = 3;
        arrays[3] = 4;
        arrays[4] = 5;
        System.out.println(arrays[5]);
        int sum = 0;
        for (int i = 0; i < arrays.length; i++) {
            sum = sum + arrays[i];
        }
        System.out.println("总和为：" + sum);
    }

    /**
     * 静态初始化
     */
    public void method02() {
        // 静态初始化
        int[] numbers = {1, 3, 4, 5, 5, 6};
        Student[] student = {new Student("张三", "20"), new Student("里斯", "32")};
        student[0] = new Student("张三风", "20");
        System.out.println("numbers[1] = " + numbers[2]);
        System.out.println("student[0] = " + student[0]);
    }

    /**
     * 动态初始化
     */
    public void method03() {
        // 动态初始化
        int[] numbers = new int[10];
        // 对数组进行赋值
        numbers[0] = 1;
        numbers[1] = 2;
        numbers[2] = 3;
        numbers[3] = 4;
        // 动态初始化
        Student[] students = new Student[3];
        // 动态对数组进行赋值
        students[0] = new Student("小明", "20");
        students[1] = new Student("小红", "18");
        System.out.println("numbers[0] = " + numbers[0]);
        System.out.println("students[5] = " + students[5]);
    }

    public void method04() {
        // 1、声明一个int类型的数组
        int[] numbers;
        // 2、创建一个int类型的数组
        numbers = new int[10];
        // 3、对数组进行赋值
        numbers[0] = 1;
        numbers[1] = 2;
        numbers[2] = 3;
        numbers[3] = 4;
        numbers[4] = 5;
        numbers[5] = 6;
        numbers[6] = 7;
        numbers[7] = 8;
        numbers[8] = 9;
        numbers[9] = 10;
        System.out.println("numbers[1] = " + numbers[11]);
    }

    public void method05() {
        // 1、声明一个int类型的数组
        int[] numbers;
        // 2、创建一个int类型的数组
        numbers = new int[10];
        // 3、对数组进行赋值
        numbers[0] = 1;
        numbers[1] = 2;
        System.out.println(numbers[11]);
    }


    public static void main(String[] args) {
        new ArrayDemo().method05();
    }

}
